package com.hetao.jmb2c.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hetao.jmb2c.entity.Category;
import com.hetao.jmb2c.mapper.CategoryMapper;
import com.hetao.jmb2c.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Override
    public IPage<Category> getPage(Long current, Long pageSize, String name) {
        //pageInfo描述的是页面的规格信息，当前第几页，一页多少条数据
        IPage<Category> pageInfo=new Page<>(current,pageSize);
        //构建查询条件，相当于sql中的where
        LambdaQueryWrapper<Category> wrapper = new LambdaQueryWrapper<>();
        //StringUtils.hasText(name)判断name是否为空，不为空则构建查询条件
        wrapper.like(StringUtils.hasText(name),Category::getName, name);

        IPage<Category> page = this.page(pageInfo, wrapper);
        return page;
    }
}
